package Song.Han.Demo01;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/*
    Socket(String host, int port)创建一个流套接字并将其连接到指定的主机的指定端口号
    参数：
        String host:服务器主机的名称/服务器的IP地址
        int port:服务器的端口号
    成员方法：
        OutputStream getOutputStream()
        InputStream getInputStream()
        void close()
*/
public class TCPClient {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("192.168.1.3",8888);

        OutputStream os = socket.getOutputStream();
        os.write("你好服务器".getBytes());

        InputStream is = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println(new String(bytes,0,len));

        socket.close();
    }
}
